//
//  NewSongCollectionViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/13.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "NewSongCollectionViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@interface NewSongCollectionViewCell ()
//背景图
@property(nonatomic, retain) UIView *backView;
//图片
@property(nonatomic, retain) UIImageView *picUrlImageView;
//名字
@property(nonatomic, retain) UILabel *nameLabel;
@end
@implementation NewSongCollectionViewCell
- (void)dealloc {
    [_backView release];
    [_picUrlImageView release];
    [_nameLabel release];
    [_listenDataModel release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //创建视图
        [self createSubView];
    }
    return self;
}
#pragma mark 创建视图
- (void)createSubView {
    //大背景图片
    self.backView = [[UIView alloc]init];
    self.backView.backgroundColor = [UIColor whiteColor];
    self.backView.alpha = 0.05;
    [self.contentView addSubview:self.backView];
    [self.backView release];
    
    //图片
    self.picUrlImageView = [[UIImageView alloc]init];
    //    self.picUrlImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.picUrlImageView];
    [self.picUrlImageView release];
    
    //标题
    self.nameLabel = [[UILabel alloc]init];
    //    self.nameLabel.backgroundColor = [UIColor orangeColor];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont systemFontOfSize:13];
    self.nameLabel.numberOfLines = 2;
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel release];
    
}
#pragma mark 设置大小
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    //大背景图片
    self.backView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    //图片
    self.picUrlImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 40);
    //名称
    self.nameLabel.frame = CGRectMake(0, self.picUrlImageView.frame.size.height, self.picUrlImageView.frame.size.width, 40);
}
#pragma mark 重写listenDataModel的setter方法
- (void)setListenDataModel:(ListenDataModel *)listenDataModel {
    if (_listenDataModel != listenDataModel) {
        [_listenDataModel release];
        _listenDataModel = [listenDataModel retain];
    }
    //图片
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:listenDataModel.picUrl]];
    //名称
    self.nameLabel.text = listenDataModel.name;
}

@end
